import { useState, useEffect } from 'react'
// 定时器
export function useTimer() {
  const [count, setCount] = useState(0)
  // 定时器
  useEffect(() => {
    const T = setInterval(() => {
      setCount((count) => count + 1)
      // setCount( count + 1) // 永远是1
    }, 1000)
    // 销毁
    return () => {
      clearInterval(T)
    }
  }, [])
  return [count]
}
